﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using MINERP.MODEL.EM;


namespace MINERP.DAL.EM
{
    public  class DepartMentDAL:IDisposable
    {
        public DepartmentInfo Select(int id)
        {
            DepartmentInfo objInfo = new DepartmentInfo();
            string strSQL = string.Format("SELECT * FROM tb_WorkerGroup Where GroupId ={0}", id);
            
            using (SqlDataReader rdr = SqlHelper.ExecuteReader(SqlHelper.ConnString, CommandType.Text, strSQL,null))
            {
                if (rdr.Read())
                {
                    objInfo = new DepartmentInfo();
                    objInfo.Id = Convert.ToInt32(rdr["GroupId"]);
                    objInfo.DepName = rdr["GroupName"].ToString();
                }
            }
            return objInfo;
        }


        public List<DepartmentInfo> SelectAll()
        {
            List<DepartmentInfo> list = new List<DepartmentInfo>();
            DepartmentInfo objInfo = new DepartmentInfo();
            string strSQL = "SELECT * FROM tb_WorkerGroup";

            using (SqlDataReader rdr = SqlHelper.ExecuteReader(SqlHelper.ConnString, CommandType.Text, strSQL, null))
            {
                while(rdr.Read())
                {
                    objInfo = new DepartmentInfo();
                    objInfo.Id = Convert.ToInt32(rdr["GroupId"]);
                    objInfo.DepName = rdr["GroupName"].ToString();
                    list.Add(objInfo);
                }
            }
            return list;
        }

        #region IDisposable 成员
        public void Dispose()
        {
            GC.SuppressFinalize(this);
        }
        #endregion
     

    }
}
